home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS26.ADF / HexDump / HexDump1.mod < prev    next >
Text File  |  1989-01-26  |  4KB  |  98 lines

  1. MODULE HexMemoryDump;
  2. (*$S-,$T-,$A+*)
  3. (* This program dumps the hex listing of memory. *)
  4.  
  5. FROM InOut         IMPORT WriteString, WriteLn;
  6.  
  7. FROM SYSTEM        IMPORT LONGWORD, ADDRESS, TSIZE;
  8.  
  9. FROM AMIGAX        IMPORT CLinePtr, CLineLen;
  10.  
  11. FROM Hex           IMPORT ConvertHexStringToCardinal, HexDump, WriteHex,
  12.                           WriteChar, str80, OutType, CharType, LeftByte,
  13.                           RightByte, CharOut, CharIndex;
  14.  
  15. FROM HexParser     IMPORT LineFeed, IsAlpha, IsDelimiter, IsDigit;
  16.  
  17. VAR
  18.    StartingLocation : str80;     (* String for starting location *)
  19.    EndingLocation   : str80;     (* String for ending location *)
  20.    Out              : OutType;   (* Output array *)
  21.    Start            : LONGCARD;  (* Value of starting address *)
  22.    End              : LONGCARD;  (* Value of ending address *)
  23.    Delta            : LONGCARD;  (* Number of bytes to output times 2 *)
  24.    StartDump        : LONGWORD;  (* Where to start dump *)
  25.    StartDumpPtr     : ADDRESS;   (* Address of where to start dump *)
  26.    FirstParameter   : BOOLEAN;   (* First parameter flag *)
  27.    SecondParameter  : BOOLEAN;   (* Second parameter flag *)
  28.    x                : LONGCARD;  (* Dummy counter *)
  29.    y,z              : CARDINAL;  (* Counter because array can not use
  30.                                     LONGCARD index *)
  31.  
  32. BEGIN
  33. (* Initialize parameters. *)
  34.    Start := 0;
  35.    CharIndex := 1;
  36.    FirstParameter := FALSE;
  37.    SecondParameter := FALSE;
  38. (* Read input line and generate an ASCII string. *)
  39.    FOR x := 1 TO CLineLen DIV 2 DO
  40.       WriteHex(CARDINAL(CLinePtr^),LeftByte,RightByte,Out);
  41.       WriteChar(CharOut,CharIndex,LeftByte,RightByte);
  42.       INC(CLinePtr,TSIZE(CARDINAL));
  43.    END; (* FOR *)
  44. (* Initialize array indices. *)
  45.    y := 1;
  46.    z := 1;
  47.    FOR x := 1 TO CLineLen DO
  48. (* Perform parser on input string. *)
  49.       IF ((NOT IsDelimiter(CharOut,z)) AND (NOT LineFeed(CharOut,z))) THEN
  50.          IF (NOT IsDigit(CharOut,z)) THEN
  51.             IF (NOT IsAlpha(CharOut,z)) THEN
  52.             (* Unknown character! *)
  53.                WriteString('Unknown character!');WriteLn;
  54.             ELSE
  55.             (* If alpha character determine if first parameter or second
  56.                parameter and put in proper string. *)
  57.                IF (NOT FirstParameter) THEN
  58.                   StartingLocation[y-1] := CAP(CharOut[z]);
  59.                ELSE
  60.                   EndingLocation[y-1] := CAP(CharOut[z]);
  61.                END;
  62.             END;
  63.          ELSE
  64.          (* If digit character determine if first parameter or second
  65.             parameter and put in proper string. *)
  66.             IF (NOT FirstParameter) THEN
  67.                StartingLocation[y-1] := CAP(CharOut[z]);
  68.             ELSE
  69.                EndingLocation[y-1] := CAP(CharOut[z]);
  70.             END;
  71.          END;
  72.       ELSE
  73.       (* If delimiter or line feed then calculate the start or end
  74.          value. *)
  75.          IF (NOT FirstParameter) THEN
  76.             FirstParameter := TRUE;
  77.             ConvertHexStringToCardinal(Start,StartingLocation);
  78.             (* Initialize array parameter for second parameter string. *)
  79.             y := 0;
  80.          ELSE
  81.             SecondParameter := TRUE;
  82.             ConvertHexStringToCardinal(End,EndingLocation);
  83.          END;
  84.       END;   
  85. (* Increment array indices. *)
  86.       y := y + 1;
  87.       z := z + 1;
  88.    END; (* FOR *)
  89. (* Calculate the number of bytes to output. *)
  90.    Delta := (End - Start) DIV 2;
  91. (* Initialize the character index. *)
  92.    CharIndex := 1;
  93. (* Calculate starting address. This is critical to proper operation. *)
  94.    StartDump := LONGWORD(Start);
  95.    StartDumpPtr := ADDRESS(StartDump);
  96. (* Dump memory and ASCII equivalent. *)
  97.    HexDump(StartDumpPtr,Delta,Out);
  98. END HexMemoryDump.